<?php
/**
 * SellerHome.php
 *
 * @copyright  2023 opencart.cn - All Rights Reserved
 * @link       http://www.guangdawangluo.com
 * @author     TL <mengwb@opencart.cn>
 * @created    2023-06-01 15:09:14
 * @modified   2023-06-01 15:09:14
 */

namespace Plugin\MultiSeller\Http\Controllers\Shop\Seller;

use Beike\Seller\Repositories\ProductRepo;
use Beike\Seller\Repositories\SellerRepo;
use Beike\Shop\Http\Resources\ProductSimple;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;

class HomeController
{
    /**
     * @return View
     */
    public function index(Request $request, int $id): View
    {
        $products = ProductRepo::getBuilder(['active' => true, 'order' => 'desc'], $id)->reorder('products.position_seller')->paginate($data['per_page'] ?? 20);

        $seller = SellerRepo::find($id);
        if (! $seller) {
            return view('errors.404');
        }
        $data     = [
            'seller'   => $seller,
            'products' => $products,
            'items'    => ProductSimple::collection($products)->jsonSerialize(),
        ];

        return view('MultiSeller::shop.seller.index', $data);
    }
}
